<!DOCTYPE html>
<html lang="en">

<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>第 01 题</title>
	<script type="text/javascript">
		/*
			用户输入一个整数n：
				求1! + 2! + 3! + 4! + …… + n!的和
				叹号表示阶乘，如4! = 1 * 2 * 3 * 4
		*/

		window.onload = function () {
			// 用户输入 
			var oInput = parseInt(prompt("请输入一个正整数")),
				oNumber = oInput >= 1 ? true : false;



			// 循环
			if (oNumber) {
				var oSum = 0;
				for (var oNume = 1; oNume <= oInput; oNume++) {
					// 累乘
					var oMult = 1;
					for (var a = 1; a <= oNume; a++) {
						oMult = oMult * a;
					}
					oSum += oMult
				}
				console.log("1!+...+" + oInput + "! 的结果为：" + oSum);
				document.getElementsByTagName('body')[0].style.cssText = "width: 100%; height: 100%;text-align: center;font-size: 36px;line-height: 100vh;overflow: hidden;";
				document.getElementsByTagName('body')[0].innerHTML = "1!+...+" + oInput + "! 的结果为：" + oSum;
			} else {
				document.getElementsByTagName('body')[0].innerHTML = "输入错误！请从新输入！";
				document.getElementsByTagName('body')[0].style.cssText = "width: 100%; height: 100%;text-align: center;font-size: 36px;line-height: 100vh;overflow: hidden;color: red;";
				console.log('%cError: 输入错误！', 'color: red;');
				setTimeout(() => { location.reload(); }, 3000);

			}
		}
	</script>
</head>

<body>

</body>

</html>